<template>
  <span class="tools-li">
    <transition name="el-zoom-in-top">
      <div v-show="isShow" :key="tooltipId" ref="customAlert" class="custom-demo" transiton="el-zoom-in-center">
        <div class="con">
          <div class="myself-header">
            <div class="header-body"><i class="el-icon-date" />日历</div>
          </div>
          <div class="now-data-myself">
            <div style="width: 100%;height: 100%" class="myself-body">
              <div class="now-data-myself-time">{{ date }}</div>
              <div class="now-data-myself-week">{{ week }}</div>
            </div>
          </div>
          <Calendar />
        </div>
      </div>
    </transition>
    <slot name="reference" />
  </span>
</template>

<script>
import { generateId } from 'element-ui/src/utils/util';
import Calendar from 'vue-calendar-component';
export default {
  name: 'PcDateTools',
  components: { Calendar },
  props: {
    trigger: {
      type: String,
      default: 'click',
      validator: value => ['click', 'focus', 'hover', 'manual'].indexOf(value) > -1
    }
  },
  data() {
    return {
      isShow: false,
      isLogin: false,
      date: '',
      week: '',
      systemList: []
    };
  },
  computed: {
    tooltipId() {
      return `el-custom-popover-${generateId()}`;
    }
  },
  created() {
    const now = new Date();
    this.date = now.getDate();// 得到日期
    const day = now.getDay();// 得到周几
    const arr_week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    this.week = arr_week[day];
  },
  mounted() {
    if (this.trigger === 'click' && undefined !== this.$refs.customAlert) { // click 事件
      this.$refs.customAlert.addEventListener('click', this.triggerOnClick);
    }
    if (this.trigger === 'hover' && undefined !== this.$refs.customAlert) {
      this.$refs.customAlert.addEventListener('mouseenter', this.triggerOpen);
      this.$refs.customAlert.addEventListener('mouseleave', this.triggerClose);
    }
  },
  destroyed() {
    if (this.trigger === 'click' && undefined !== this.$refs.customAlert) { // click 事件
      this.$refs.customAlert.removeEventListener('click', this.triggerOnClick);
    }
    if (this.trigger === 'hover' && undefined !== this.$refs.customAlert) {
      this.$refs.customAlert.removeEventListener('mouseenter', this.triggerOpen);
      this.$refs.customAlert.removeEventListener('mouseleave', this.triggerClose);
    }
  },
  methods: {
    triggerOnClick() {
      if (this.isShow) {
        this.isShow = false;
      } else {
        this.isShow = true;
      }
    },
    triggerOpen() {
      this.isShow = true;
      this.$emit('callBack', this.isShow);
    },
    triggerClose() {
      this.isShow = false;
      this.$emit('callBack', this.isShow);
    }
  }
};
</script>

<style scoped>
.custom-demo {
  position: absolute;
  top: 70px;
  right: 140px;
  width: 280px;
  height: 300px;
  z-index: 100;
}
.myself-header {
  height: 40px;
  width: 100%;
  background-color: #ffffff;
  line-height: 40px;
  padding: 0px 10px;
  box-sizing: border-box;
}
.header-body {
  border-bottom: 1px solid rgba(227, 227, 227, 0.6);
  width: 100%;
  height: 100%;
  font-size: 16px;
  color: #1e389e;
  font-weight: 500;
  letter-spacing: 10px;
}
.now-data-myself {
  padding: 0px 10px;
  box-sizing: border-box;
  width: 40%;
  position: absolute;
  text-align: center;
  height: 47px;
}
.myself-body {
  position: relative;
}
.myself-body ::before {
  content: ' ';
  position: absolute;
  right: 0px;
  top: 6px;
  height: 35px;
  width: 1px;
  background-color: #eeeeee;
}
.con {
  position: relative;
  width: 100%;
  height: 100%;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.con ::v-deep .wh_content_all {
  border-radius: 4px;
  background-color: #ffffff;
}
.con ::v-deep .wh_top_changge li {
  color: #F56C6C !important;
  font-size: 15px !important;
}
.con ::v-deep .wh_content_item, .wh_content_item_tag {
  color: #303133 !important;
}
.con ::v-deep .wh_content_item .wh_isToday {
  background: #00d985  !important;
  color: #fff  !important;
}
.con ::v-deep .wh_content_item .wh_chose_day {
  background: #409EFF  !important;
  color: #ffff  !important;
}
.con ::v-deep .wh_item_date:hover {
  background: rgb(217, 236, 255) !important;
  border-radius: 100px !important;
  color: rgb(102, 177, 255)  !important;
}
.con ::v-deep .wh_jiantou1{
  border-top: 2px solid #909399;
  border-left: 2px solid #909399;
  width: 7px;
  height: 7px;
}
.con ::v-deep .wh_jiantou2 {
  border-top: 2px solid #909399;
  border-right: 2px solid #909399;
  width: 7px;
  height: 7px;
}
.con ::v-deep .wh_top_tag{
  color: #409EFF;
  border-top: 1px solid rgba(227, 227, 227, 0.6);
  border-bottom: 1px solid rgba(227, 227, 227, 0.6);
}
.con ::v-deep .wh_container {
  max-width: 280px;
}
.con ::v-deep .wh_top_changge {
  display: flex;
  width: 50%;
  margin-left: 43%;
}
.now-data-myself-time {
  color: #F56C6C;
  font-size: 18px;
  height: 27px;
  line-height: 27px;
  font-family: "Helvetica Neue";
}
.now-data-myself-week {
  font-size: 13px;
  height: 20px;
  line-height: 20px;
  color: #909399;
}
.wh_top_changge .wh_content_li{
  font-family: Helvetica;
}
</style>
